package org.movieexample.ws;

import org.movieexample.www.movie.GetAllMovieData;
import org.movieexample.www.movie.GetAllMovieDataFault;
import org.movieexample.www.movie.GetAllMovieDataResponse;
import org.movieexample.www.movie.GetMovieByGenre;
import org.movieexample.www.movie.GetMovieByGenreFault;
import org.movieexample.www.movie.GetMovieByGenreResponse;
import org.movieexample.www.movie.GetMovieByName;
import org.movieexample.www.movie.GetMovieByNameFault;
import org.movieexample.www.movie.GetMovieByNameResponse;
import org.movieexample.www.movie.GetMovieByTheatre;
import org.movieexample.www.movie.GetMovieByTheatreFault;
import org.movieexample.www.movie.GetMovieByTheatreResponse;
import org.movieexample.www.movie.GetMovieByTime;
import org.movieexample.www.movie.GetMovieByTimeFault;
import org.movieexample.www.movie.GetMovieByTimeResponse;
import org.movieexample.www.movie.GetMovieByType;
import org.movieexample.www.movie.GetMovieByTypeFault;
import org.movieexample.www.movie.GetMovieByTypeResponse;
import org.movieexample.www.movie.MovieData;
import org.movieexample.www.movie.MovieList;

import org.movieexample.ws.MovieServiceSkeletonInterface;


public class MovieBusiness implements MovieServiceSkeletonInterface
{

	
	@Override
	public GetMovieByTypeResponse getMovieByType(
			GetMovieByType getMovieByType)
			throws GetMovieByTypeFaultException		
	{
		MovieList movielist;
		GetMovieByTypeResponse result = new GetMovieByTypeResponse();
				String movietype = getMovieByType.getIn();
				if(movietype!=null)
				{
					try
					{
						MovieDAO moviedao=new MovieDAO();
					    movielist = moviedao.getMovieInfoByType(getMovieByType.getIn());
						result.setOut(movielist);
						return result;
					}
					catch (Exception e) 
					{
						GetMovieByTypeFault fault = new GetMovieByTypeFault();
						fault.setGetMovieByTypeFault(ErrorMessages.ServiceUnavailableError);
						GetMovieByTypeFaultException typefault = new GetMovieByTypeFaultException();
						typefault.setFaultMessage(fault);
						throw typefault;
					}
					
				}
				else
				{
					GetMovieByTypeFault fault = new GetMovieByTypeFault();
					fault.setGetMovieByTypeFault(ErrorMessages.ValidationFailureError);
					GetMovieByTypeFaultException typefault = new GetMovieByTypeFaultException();
					typefault.setFaultMessage(fault);
					throw typefault;
				}		
	}

	@Override
	public GetMovieByTheatreResponse getMovieByTheatre(
			GetMovieByTheatre getMovieByTheatre)
			throws GetMovieByTheatreFaultException
	{
		MovieList movielist;
		GetMovieByTheatreResponse result = new GetMovieByTheatreResponse();
		String movietheatre = getMovieByTheatre.getIn();
		if(movietheatre != null )
		{
			try 
			{
				MovieDAO moviedao=new MovieDAO();
				movielist=moviedao.getMovieInfoByTheatre(getMovieByTheatre.getIn());
				result.setOut(movielist);
				return result;
			} 
			catch (Exception e) 
			{
				
				GetMovieByTheatreFault fault = new GetMovieByTheatreFault();
				fault.setGetMovieByTheatreFault(ErrorMessages.ServiceUnavailableError);
				GetMovieByTheatreFaultException typefault = new GetMovieByTheatreFaultException();
				typefault.setFaultMessage(fault);
				throw typefault;
			}	
		}
		else
		{
			GetMovieByTheatreFault fault = new GetMovieByTheatreFault();
			fault.setGetMovieByTheatreFault(ErrorMessages.ValidationFailureError);
			GetMovieByTheatreFaultException typefault = new GetMovieByTheatreFaultException();
			typefault.setFaultMessage(fault);
			throw typefault;
		}
		
	}

	@Override
	public GetAllMovieDataResponse getAllMovieData(
			GetAllMovieData getAllMovieData) throws GetAllMovieDataFaultException
	{
		
		MovieList movielist;
		GetAllMovieDataResponse result = new GetAllMovieDataResponse();
		try 
		{
			MovieDAO moviedao=new MovieDAO();

			movielist=moviedao.getAllMovieData();
			result.setOut(movielist);
		} 
		catch (Exception e) 
		{
			GetAllMovieDataFault  excep = new GetAllMovieDataFault();
			excep.setGetAllMovieDataFault(ErrorMessages.ServiceUnavailableError);			
			GetAllMovieDataFaultException typefault = new GetAllMovieDataFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
		
	}

	@Override
	public GetMovieByGenreResponse getMovieByGenre(
			GetMovieByGenre getMovieByGenre)
			throws GetMovieByGenreFaultException
	{
		MovieList movielist;
		GetMovieByGenreResponse result = new GetMovieByGenreResponse();
		String moviegenre = getMovieByGenre.getIn();
		if(moviegenre != null)
		{
		try 
		{
			MovieDAO moviedao=new MovieDAO();

			movielist=moviedao.getMovieInfoByGenre(getMovieByGenre.getIn());
			result.setOut(movielist);
			return result;
		} 
		catch (Exception e) 
		{
			GetMovieByGenreFault excep = new GetMovieByGenreFault();
			excep.setGetMovieByGenreFault(ErrorMessages.ServiceUnavailableError);
			GetMovieByGenreFaultException typefault = new GetMovieByGenreFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		}
		else
		{
			GetMovieByGenreFault excep = new GetMovieByGenreFault();
			excep.setGetMovieByGenreFault(ErrorMessages.ValidationFailureError);
			GetMovieByGenreFaultException typefault = new GetMovieByGenreFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
	}

	@Override
	public GetMovieByTimeResponse getMovieByTime(
			GetMovieByTime getMovieByTime)
			throws GetMovieByTimeFaultException
	{
		MovieList movielist;
		GetMovieByTimeResponse result = new GetMovieByTimeResponse();
		String movietime = getMovieByTime.getIn();
		if(movietime != null)
		{
		try 
		{
			MovieDAO moviedao=new MovieDAO();

			movielist=moviedao.getMovieInfoByTime(getMovieByTime.getIn());
			result.setOut(movielist);
			return result;
		} 
		catch (Exception e) 
		{
			GetMovieByTimeFault excep = new GetMovieByTimeFault();
			excep.setGetMovieByTimeFault(ErrorMessages.ServiceUnavailableError);
			GetMovieByTimeFaultException typefault = new GetMovieByTimeFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		}
		else
		{
			GetMovieByTimeFault excep = new GetMovieByTimeFault();
			excep.setGetMovieByTimeFault(ErrorMessages.ValidationFailureError);
			GetMovieByTimeFaultException typefault = new GetMovieByTimeFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
	}

	@Override
	public GetMovieByNameResponse getMovieByName(
			GetMovieByName getMovieByName)
			throws GetMovieByNameFaultException
	{
		MovieData movie;
		GetMovieByNameResponse result = new GetMovieByNameResponse();
		String name = getMovieByName.getIn();
		if(name != null)
		{
		try 
		{
			MovieDAO moviedao=new MovieDAO();

			movie=moviedao.getMovieInfoByName(getMovieByName.getIn());
			result.setOut(movie);
			return result;
		} 
		catch (Exception e) 
		{
			GetMovieByNameFault excep = new GetMovieByNameFault();
			excep.setGetMovieByNameFault(ErrorMessages.ServiceUnavailableError);
			GetMovieByNameFaultException typefault = new GetMovieByNameFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		}
		else
		{
			GetMovieByNameFault excep = new GetMovieByNameFault();
			excep.setGetMovieByNameFault(ErrorMessages.ValidationFailureError);
			GetMovieByNameFaultException typefault = new GetMovieByNameFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
	}
	
}
